import {ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {Globals} from "../../../../globals";
import {PageHelper} from "../../../../utils/page-helper-model";
import {BaseService} from "../../../../shared/service/base.service";
import {Router} from "@angular/router";
import {ApiUrl} from "../../../../config/api-url";
import {RoleIdEnum} from "../../../../enums/role-id.enum";
import {Consts} from "../../../../config/consts";
import {MyDateModel} from "../../../../models/my-date.model";


@Component({
  selector: 'app-withdrawals-list-head',
  templateUrl: './withdrawals-list-head.component.html',
  styleUrls: ['./withdrawals-list-head.component.less']
})
export class WithdrawalsListHeadComponent implements OnInit {

  isMobile = Globals.isMobile();

  @Input()
    // 判断显示代付打款
  isBatchDeal: any;
  // 提现参数集合
  // 提现状态
  @Input()
  withDrewStatus = -1;
  @Output()
  event: EventEmitter<any> = new EventEmitter();

  // 分页
  pageHelper: PageHelper = new PageHelper;

  isVisible: boolean;
  // 角色
  roleId: number;
  roleIdEnum = {
    SUPER_ADMINISTRATOR: RoleIdEnum.SUPER_ADMINISTRATOR,
    AGENT: RoleIdEnum.AGENT,
    MERCHANT: RoleIdEnum.MERCHANT,
  };
  isVisibleInvoice: boolean;
  failReason: any;

  // 开始日期类型
  startDateTimeType: string = 'start';
  // 结束日期类型
  endDateTimeType: string = 'end';
  // 开始日期
  startDateTime: Date;
  // 结束日期
  endDateTime: Date;


  constructor(private baseService: BaseService, private router: Router , private changeDetectorRef: ChangeDetectorRef) {
    console.log(this.withDrewStatus);

  }

  ngOnInit(): void {
    this.roleId = JSON.parse(sessionStorage.getItem(Consts.USER_INFO)).roleId;
    this.startDateTime = this.baseService.zorro.getDateTime().startOfMonth;
    this.endDateTime = this.baseService.zorro.getDateTime().endOfMonth;
  }


  submitForm() {
    this.event.emit(this.splitValidate());
  }


  // 返回参数
  splitValidate() {
    console.log(this.withDrewStatus)
    return {
      keyword: this.pageHelper.keyword,
      status: this.withDrewStatus,
      startDateTime: this.startDateTime,
      endDateTime: this.endDateTime,
    };
  }




  // 选择提现状态
  searchListByWithDrewStatus() {
    this.submitForm();
  }


  // 将开始、结束时间往外抛
  outDateTime($event: MyDateModel) {
    /**
     * date: Fri Mar 19 2021 23:59:06 GMT+0800 (中国标准时间) {}
     * type: "end"
     */
    if ($event.type == 'start') {
      this.startDateTime = $event.date;
    } else if ($event.type == 'end') {
      this.endDateTime = $event.date;
    }
  }


  showInvoice() {
    this.isVisibleInvoice = true;
  }

  eventInvoice($event: any) {
    this.isVisibleInvoice = $event;
  }
}
